package com.kzd.gtgame.jetpack.manager

import com.blankj.utilcode.util.GsonUtils
import com.kzd.gtgame.app.*
import com.kzd.gtgame.base.BaseManager
import com.kzd.gtgame.entity.*
import com.module.lemlin.http.HttpResponseData
import com.module.lemlin.http.HttpResponseDataE
import com.module.lemlin.http.HttpResponseDataT
import rxhttp.RxHttp
import rxhttp.await

class MineRepository : BaseManager() {

    /**
     * 游戏收藏列表
     * */
    suspend fun mineCollectGame(
        page: String, limit: String,
    ): HttpResponseDataE<GameBean> = RxHttp.postForm(PERSONAL_YOUXI_SHOUCANG)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 交易收藏列表
     * */
    suspend fun mineCollectBargain(
        page: String, limit: String,
    ): HttpResponseDataE<GameBargain> = RxHttp.postForm(PERSONAL_JIAOYI_SHOUCANG)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 物品收藏列表
     * */
    suspend fun mineCollectGoods(
        page: String, limit: String,
    ): HttpResponseDataE<MallGoods> = RxHttp.postForm(PERSONAL_GOODS_SHOUCANG)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 我的代金券
     * */
    suspend fun mineCouponPrice(
        type: String, page: String, limit: String,
    ): HttpResponseDataE<WelfareCoupon> = RxHttp.postForm(USER_MY_COUPON)
        .add("type", type)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 我的礼包
     * */
    suspend fun mineGiftList(
        keyword: String? = null, page: String, limit: String,
    ): HttpResponseDataE<GameGift> = RxHttp.postForm(PERSONAL_MY_LB)
        .add("keyword", keyword)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 游戏反馈类型
     * */
    suspend fun mineFeedbackType(): HttpResponseDataE<FeedbackType> =
        RxHttp.postForm(USER_GET_FEEDBACK_TYPES)
            .await()

    /**
     * 省钱卡数据
     * */
    suspend fun mineMemberMoneyCard(): HttpResponseDataT<MemberMoney> =
        RxHttp.postForm(USER_GET_SAVING_INFO)
            .await()

    /**
     * 省钱卡订单
     * */
    suspend fun mineMemberMoneyOrder(
        type: String, money: String, pay_type: String,
    ): HttpResponseDataT<String> = RxHttp.postForm(USER_SAVING_APPLY)
        .add("type", type)
        .add("money", money)
        .add("pay_type", pay_type)
        .await()

    /**
     * 会员中心数据
     * */
    suspend fun mineMemberCenterCard(): HttpResponseDataT<MemberCenter> =
        RxHttp.postForm(USER_GET_MEMBER_INFO)
            .await()

    /**
     * 会员中心订单
     * */
    suspend fun mineMemberCenterOrder(
        id: String, money: String, pay_type: String,
    ): HttpResponseDataT<String> = RxHttp.postForm(USER_MEMBER_CREATE_ORDER)
        .add("id", id)
        .add("money", money)
        .add("pay_type", pay_type)
        .await()

    /**
     * 平台币金额
     * */
    suspend fun minePlatformMoney(): HttpResponseDataT<PlatformData> =
        RxHttp.postForm(USER_GET_COIN_INFO)
            .await()

    /**
     * 平台币订单
     * */
    suspend fun minePlatformOrder(
        id: String, money: String, pay_type: String,is_have:Int
    ): HttpResponseDataT<String> = RxHttp.postForm(USER_COIN_CREATE_ORDER)
        .add("id", id)
        .add("money", money)
        .add("pay_type", pay_type)
        .add("is_have", is_have)
        .await()

    /**
     * 充值转游
     * */
    suspend fun mineTransferList(
        keyword: String, page: String, limit: String,
    ): HttpResponseDataE<GameBean> = RxHttp.postForm(NEW_APPS_GET_TURN_LIST)
        .add("keyword", keyword)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 充值转游详情
     * */
    suspend fun mineTransferDetails(game_id: String): HttpResponseDataT<GameTransfer> =
        RxHttp.postForm(NEW_APPS_GET_TURN_DETAIL)
            .add("game_id", game_id)
            .await()

    /**
     * 充值转游信息
     * */
    suspend fun mineTransferInfo(game_id: String): HttpResponseDataT<TransferInfo> =
        RxHttp.postForm(PERSONAL_GET_TURN_INFO)
            .add("game_id", game_id)
            .await()

    /**
     * 转游角色
     * */
    suspend fun mineTransferRole(
        appid: String, servers_id: String? = null,
    ): HttpResponseDataE<TransferRole> {
        val http = RxHttp.postForm(PERSONAL_GET_ROLE_LIST)
            .add("appid", appid)
        if (!servers_id.isNullOrEmpty()) {
            http.add("servers_id", servers_id)
        }
        return http.await()
    }

    /**
     * 充值转游提交申请
     * */
    suspend fun mineTransferApply(
        gid: String,
        roleid: String,
        turn_gid: String,
        turn_roleid: String,
    ): HttpResponseData =
        RxHttp.postForm(PERSONAL_SET_TURN)
            .add("gid", gid)
            .add("roleid", roleid)
            .add("turn_gid", turn_gid)
            .add("turn_roleid", turn_roleid)
            .await()

    /**
     * 我的游戏
     * */
    suspend fun mineMyGame(): HttpResponseDataE<GameBean> =
        RxHttp.postForm(USER_MY_GAME)
            .await()

    /**
     * 我的评论
     * */
    suspend fun mineMyDiscuss(
        page: String, limit: String,
    ): HttpResponseDataE<MineDiscuss> = RxHttp.postForm(NEW_APPS_MY_PINGLUN)
        .add("type", "0")
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 积分记录
     * */
    suspend fun mineMyOrder(
        type: Int, page: String, limit: String,
    ): HttpResponseDataE<MineOrder> = RxHttp.postForm(PERSONAL_GET_MY_ORDER)
        .add("type", type)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 中奖记录
     * */
    suspend fun mineMyLottery(
        page: String, limit: String,
    ): HttpResponseDataE<MineLottery> =
        RxHttp.postForm(APP_CHOUJIANG_LOG)
            .add("p", page)
            .add("limit", limit)
            .await()

    /**
     * 消息中心
     * */
    suspend fun mineMessage(
        page: String, limit: String,
    ): HttpResponseDataE<UserMessage> = RxHttp.postForm(NEW_APPS_MESSAGE)
        .add("p", page)
        .add("limit", limit)
        .await()

    /**
     * 全部已读
     * */
    suspend fun mineMessageRead(): HttpResponseData =
        RxHttp.postForm(NEW_APPS_MESSAGE_READ)
            .await()

    /**
     * 消息中心
     * */
    suspend fun mineFeedback(feedback: Feedback): HttpResponseData {
        val maps: Map<String, String?> =
            GsonUtils.fromJson<Map<String, String?>>(
                GsonUtils.toJson(feedback),
                Map::class.java
            ).filter { it.value != null }
        return RxHttp.postForm(USER_FEEDBACK)
            .addAll(maps)
            .await()
    }

    /**
     * 消息中心
     * */
    suspend fun mineFeedbackGame(
        page: String, limit: String,
    ): HttpResponseDataE<GameFeedback> = RxHttp.postForm(NEW_APPS_GET_GAME_LIST)
        .add("p", page)
        .add("limit", limit)
        .await()
}